# 导入模块
import keyword

import cv2

# 摄像头
cap = cv2.VideoCapture(0)
flag = 1
num = 1
while (cap.isOpened()):  # 检测是否在开启状态
    ret_flag, Vshow = cap.read()  # 得到每帧图像
    cv2.imshow('capture_test', Vshow)  # 显示图像
    keyboard = cv2.waitKey(1)  # 按键判断
    if keyboard == ord('s'):  # 保存
        cv2.imwrite('D:/Programming_Softwares/OpenCV/photoes/' + str(num) + '.jpg', Vshow)
        print("成功保存！" + str(num) + '.jpg')
        print('====================')
        num = num + 1
    elif keyboard == ord(' '):
        break
# 释放摄像头
cap.release()
# 释放内存
cv2.destroyAllWindows()
